1. // for sequernce in sale order empty row

SELECT (t1.transaction_id + 1) as gap_starts_at, (SELECT MIN(t3.transaction_id) -1 FROM
 gd_sales_order t3 WHERE t3.transaction_id > t1.transaction_id) as gap_ends_at FROM
 gd_sales_order t1 WHERE NOT EXISTS (SELECT t2.transaction_id FROM gd_sales_order t2
  WHERE t2.transaction_id = t1.transaction_id + 1) HAVING gap_ends_at IS NOT NULL


 2. // for insert purchase order

 INSERT INTO `gd_purchase_order`(`transaction_id`, `shipment_number`, `qty`, `cost`, `amount`, `Status`, `user_id`, `pid`)
 SELECT Orderno, Shipno,Qty,cost,Qty*cost,'y',userid,Pid FROM `gd_transin` WHERE `Shipno` LIKE '899'


 3. // insert sales order

 INSERT INTO `gd_sales_order`(`transaction_id`, `invoice`, `qty`, `prices`, `amount`, `Status`, `user_id`, `pid`)
 SELECT Orderno, invoice_number,Qty,prices,Qty*prices,"y",userid,pid FROM `gd_transout` WHERE  Orderno =14650


 4. //

 SELECT a.Orderno,a.Date,a.invoice_number,a.dispatched_qty,a.dispatch_date,dispatched_status,
 g_confirm,concat(d.Partno," ",d.Model," ",d.Maker," ",d.Description) as product ,c.Location,b.name, SUM( a.qty ) as qty ,
 d.*, a.Prices * SUM( a.qty ) AS Amount
 FROM  `gd_transout` AS a
 INNER JOIN gdsales  AS b ON a.invoice_number = b.invoice_number
 inner join gd_godownname  AS c on a.Gid=c.Gid
 INNER JOIN gd_product AS d on a.pid=d.pid WHERE d.brand='AAA'
 GROUP BY a.pid ,a.Gid
 ORDER BY `c`.`Location`  ASC


 5. //sales godownsie
 SELECT count(*),date(a.date),group_concat(DISTINCT(d.username)) as user ,sum(a.qty) as qtyy,b.Location FROM `gd_transout` as a
  inner join gd_godownname as b on a.Gid=b.Gid INNER join gd_product as c on a.pid= c.pid
 inner join users as d on a.userid=d.user_id where status='y'
 GROUP by a.gid,date(a.date) ORDER BY `b`.`Location` DESC

 6. //change rate by percentage

update gd_product set  price=price-(price*0.05) where pid in(select concat(a.pid,",") from gd_product
 as a inner join gd_stock as b on a.pid=b.pid where brand ='KYB' group by b.pid having sum(qty)>0
)

7.//Update IDs From One table to another
update gd_product set brnd_id=(select brnd_id from tbl_brand where gd_product.Brand=tbl_brand.brnd_name)